package com.onlineClass.edu.controller;

import com.onlineClass.edu.base.BaseApiController;
import com.onlineClass.edu.base.BaseResponse;
import com.onlineClass.edu.entity.requestDto.RegisterReqDTO;
import com.onlineClass.edu.service.IRegisterService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @author 邓辉
 * @ClassName RegisterController
 * @date 2024-05-02 14:34
 */
@RestController
@RequestMapping("register")
@Slf4j
@ApiOperation(value = "用户注册",notes ="用户注册" )
public class RegisterController extends BaseApiController {
    @Autowired
    private IRegisterService iRegisterService;
    @PostMapping
    public BaseResponse register(@RequestBody RegisterReqDTO dto){
        String userName = dto.getUserName();
        if (StringUtils.isEmpty(userName)){
            log.error("[用户名为空]");
            return setResultError("[用户名为空]");
        }
        String password = dto.getPassword();
        if (StringUtils.isEmpty(password)){
            log.error("[密码为空]");
            return setResultError("[密码为空]");
        }

        return iRegisterService.register(dto)?setResultSuccess():setResultError("注册失败");
    }
}
